package com.jinyi.wwdeng.pro;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.jinyi.base.base.BaseFragment;
import com.jinyi.base.mvp.BasePresenter;
import com.jinyi.base.mvp.IBaseView;

/**
 * @Author：wwdeng
 * @Time：2024/4/14 18:18
 * <pre>
 *
 * </pre>
 */
public abstract class ProMvpFragment<V extends IBaseView, P extends BasePresenter> extends ProFragment {
    public P presenter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        initPresenter();
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    /**
     * 初始化Presenter
     */
    private void initPresenter() {
        presenter = createPresenter();
        presenter.attachView((V) this);
    }

    /**
     * 创建Presenter
     *
     * @return
     */
    public abstract P createPresenter();

    @Override
    public void onDestroy() {
        super.onDestroy();
        presenter.detachView();
    }
}